// package-star/pages/brand-distributor-stats/index.js
import { ManageTargetInfoUpdateMixins, PageScrollListMixins } from '../../../behaviors/page';
import { PACKAGE_ACTIVITY_PAGE } from '../../../constants/route';
import { navTo, showLoading, hideLoading } from '../../../common/env';
import { statsDistributorRank } from '../../../api/brd';
let distributorId;

Page({
    mixins: [ManageTargetInfoUpdateMixins, PageScrollListMixins],
    data: {
        statsInfo: {},
    },
    onLoad(options) {
        distributorId = options.distributorId;
    },
    async _handleGetList(pageNo) {
        !this.data.loaded && showLoading('加载中...');
        const { pageData } = this.data;
        let { ts } = pageData;
        pageNo === 1 && (ts = Date.now());
        const { rows = [], total } = await statsDistributorRank({ pageNo, ts, distributorId });
        this.setData({
            pageData: {
                ...pageData,
                refresh: false,
                ts,
                pageNo,
                total,
                rows: pageNo == 1 ? rows : [...pageData.rows, ...rows],
            },
        });
        if (!this.data.loaded) hideLoading(); this.setData({ loaded: true });
    },
    handleNavToActivityStats(e) {
        const { manageTargetId } = this.data;
        const { activityId } = e.currentTarget.dataset;
        navTo(PACKAGE_ACTIVITY_PAGE['activityStats'], {
            showDistributeStats: true,
            brandId: manageTargetId,
            activityId,
        });
    },
})